<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateRefereesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('referees', function (Blueprint $table) {
            $table->id();
            $table->bigInteger('user_id')->unsigned()->unique()->comment('用户ID');
            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
            $table->string('name', 50)->comment('姓名');
            $table->string('phone', 11)->comment('手机号');
            $table->string('province')->comment('省份');
            $table->string('city')->comment('城市');
            $table->bigInteger('dealer_id')->nullable()->unsigned()->comment('经销商ID');
            $table->foreign('dealer_id')->references('id')->on('dealers')->onDelete('restrict');
            $table->string('interest')->nullable()->comment('兴趣爱好');
            $table->integer('point_total')->default(0)->comment('获得积分总数');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('referees');
    }
}
